package com.atguigu.gmall.search.config;

import com.atguigu.gmall.common.consts.GmallConsts;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {
    //创建死信队列 交换机 绑定
    @Bean
    public TopicExchange deadExchange(){
        return ExchangeBuilder.topicExchange("spu_dead_exchange")
                    .durable(true)
                    .ignoreDeclarationExceptions()
                    .build();
    }

    @Bean
    public Queue deadQueue(){
        return QueueBuilder.durable("spu_dead_queue")
                            .build();
    }
    @Bean
    public Binding deadBinding(TopicExchange deadExchange,Queue deadQueue){
        return BindingBuilder.bind(deadQueue).to(deadExchange)
                            .with("spu.dead");
    }
    //创建业务交换机 队列 绑定
    @Bean
    public TopicExchange spuSaveExchange(){
        return ExchangeBuilder.topicExchange(GmallConsts.SAVE_SPU_EXCHANGE_NAME)
                .durable(true)
                .ignoreDeclarationExceptions()
                .build();
    }

    @Bean
    public Queue spuSaveQueue(){
        return QueueBuilder.durable(GmallConsts.SAVE_SPU_QUEUE_NAME)
                .deadLetterExchange("spu_dead_exchange")
                .deadLetterRoutingKey("spu.dead")
                .build();
    }
    @Bean
    public Binding spuSaveBinding(TopicExchange spuSaveExchange,Queue spuSaveQueue){
        return BindingBuilder.bind(spuSaveQueue).to(spuSaveExchange)
                .with(GmallConsts.SAVE_SPU_ROUTING_KEY);
    }


}
